$(document).ready(function(){
	search(new page());
});

/**
 * 定义分页全局变量
 */
var page_ = new page({search:search,callback:func});

/**
 * 定义容器全局变量
 */
var con = new container({
	datagrid:'#datagrid',
	datagridtoolbar:'#datagrid-toolbar', 
	singleSelect:true});

/**
 * 查询
 * @param page
 */
function search(pg){
	var url = ctx + "/message/query";
	page_.pageSize = pg.pageSize;
	page_.pageNumber = pg.pageNumber;
	query(url, getCondition(), con, page_);
}

/**
 * 获取查询条件
 * @returns {condition}
 */
function getCondition(){
	
	var condition = {};
	
	return condition;
}

/**
 * @param data
 */
function func(data){
	$.each(data,function(index,item){
		item.url = '<a href="' + ctx + '/' + item.url +'" target="" style="pointer:cursor;color:blue">' + item.url + '</a>';
	});
	page_.data.rows = data;
	$(con.datagrid).datagrid({onClickCell:function(index,field,value){
		if(field == 'url'){
			$(con.datagrid).datagrid('selectRow',index);
			var row = getSelectedRow(con.datagrid);
			if(!row){
				return;
			}
			$.ajax({
		        type: "POST",
		        url: ctx + '/message/update',
		        dataType : "json",
		        data : {id:row.id},
		        success : function(data) {
		        	if(!showMsg(data)){
        				return;
        			}
		        }
		    });
		}
	}});
}